﻿using System;
using System.IO;

namespace SharpOSCAR.Base
{
    /// <summary>
    /// Defines the base contract for all data that is transported across the network
    /// </summary>
    public abstract class ProtocolData
    {
        /// <summary>
        /// Converts the object into a byte array
        /// </summary>
        /// <returns>Returns a byte array representing the object</returns>
        public abstract byte[] ToByteArray();

        /// <summary>
        /// Writes the value of the object into a stream
        /// </summary>
        /// <param name="s">Stream to write into</param>
        public void WriteToStream(Stream s)
        {
            byte[] val = this.ToByteArray();
            s.Write(val, 0, val.Length);
        }
    }
}
